package list;

class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}

public class ConvertBinaryNumLinkedlistToInt_1290 {
    public static int getDecimalValue(ListNode head) {
        int ans = 0;

        while (head != null) {
            ans = ans * 2 + head.val;
            head = head.next;
        }

        return ans;
    }

    public static void main(String[] args) {
        ListNode acha = new ListNode(1);
        acha.next = new ListNode(0);
        acha.next.next = new ListNode(1);

        System.out.println(getDecimalValue(acha));
    }
}
